package io.framework.modules.hpinfo.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.framework.common.constant.Constant;
import io.framework.common.page.PageData;
import io.framework.common.service.impl.CrudServiceImpl;
import io.framework.common.utils.ConvertUtils;
import io.framework.modules.hpinfo.dao.VTHpglJsdwinfoDao;
import io.framework.modules.hpinfo.dto.VTHpglJsdwinfoDTO;
import io.framework.modules.hpinfo.entity.VTHpglJsdwinfoEntity;
import io.framework.modules.hpinfo.service.VTHpglJsdwinfoService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.List;
import java.util.Map;

/**
 * 环境影响评价管理-环评建设单位信息
 *
 * @author Gujq email
 * @since 1.0.0 2020-03-19
 */
@Service
public class VTHpglJsdwinfoServiceImpl extends CrudServiceImpl<VTHpglJsdwinfoDao, VTHpglJsdwinfoEntity, VTHpglJsdwinfoDTO> implements VTHpglJsdwinfoService {

    @Autowired
    VTHpglJsdwinfoDao jsdwinfoDao;

    @Override
    public QueryWrapper<VTHpglJsdwinfoEntity> getWrapper(Map<String, Object> params){
        String id = (String)params.get("id");

        QueryWrapper<VTHpglJsdwinfoEntity> wrapper = new QueryWrapper<>();
        wrapper.eq(StringUtils.isNotBlank(id), "id", id);

        return wrapper;
    }

    @Override
    public int bindJsdwInfo(Map<String, Object> params) {

        return baseDao.bindJsdwInfo(params);
    }

    @Override
    public List<Map<String, Object>> getAllInfoToSelect(Map<String, Object> params) {

        return baseDao.getAllInfoToSelect(params);
    }

    @Override
    public PageData<VTHpglJsdwinfoDTO> pages(Map<String, Object> params) {

        IPage<VTHpglJsdwinfoEntity> pages = getPage(params, Constant.CREATE_TIME, false);

        List<VTHpglJsdwinfoEntity> list = baseDao.getList(params);
        return getPageData(list,pages.getTotal(),VTHpglJsdwinfoDTO.class);
    }

    @Override
    public VTHpglJsdwinfoDTO getProjectInfoByProjectId(String id){

        List<VTHpglJsdwinfoEntity> jsdwinfoEntitys = jsdwinfoDao.getProjectInfoByProjectId(id);
        VTHpglJsdwinfoEntity vtHpglJsdwinfoEntity =new VTHpglJsdwinfoEntity();
        if(!CollectionUtils.isEmpty(jsdwinfoEntitys)){
            vtHpglJsdwinfoEntity = jsdwinfoEntitys.get(0);
        }

        return ConvertUtils.sourceToTarget(vtHpglJsdwinfoEntity,VTHpglJsdwinfoDTO.class);
    }

}